package com.jokey.vue.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author: JokeyZheng
 * @email: zhengjingfeng@ruqimobility.com
 * @created: 2021/11/26 18:19
 * @version: v1.0.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespBean<T> {

    private Integer status;

    private String msg;

    private T obj;

    private RespBean(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public static RespBean build() {
        return new RespBean<>(200, "成功");
    }

    public static RespBean ok(String msg) {
        return new RespBean<>(200, msg, null);
    }

    public static <T> RespBean ok(T obj) {
        return new RespBean<>(200, "成功", obj);
    }

    public static <T> RespBean ok(String msg, T obj) {
        return new RespBean<>(200, msg, obj);
    }

    public static RespBean error(String msg) {
        return new RespBean<>(500, msg, null);
    }

    public static <T> RespBean error(String msg, T obj) {
        return new RespBean<>(500, msg, obj);
    }


    public RespBean setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public RespBean setStatus(Integer status) {
        this.status = status;
        return this;
    }

    public RespBean setObj(T obj) {
        this.obj = obj;
        return this;
    }

}
